<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html>
<html>
	<head>
		<base href="<%=basePath %>">
		<meta charset="UTF-8">
		<title>Insert title here</title>
		<link rel='stylesheet' href="static/lib/layui/css/layui.css">
	</head>
	<body>
		<div style="width:100px" class="layui-input-block layui-input-inline">
			<select id='selecttext'>
				<option value="">请选择</option>
				<option value="n_context">内容</option>
				<option value="n_title">标题</option>
			</select>
		</div>
		<input type="text" id='checktext' style="width:200px;height:28px">
		<table class="layui-table" lay-data="{toolbar:'#toolbar', url:'notice/list', page:true, id:'datalist'}"
			lay-filter="datalist">
			<thead>
				<tr>
					<th lay-data="{field:'n_title'}">标题</th>
					<th lay-data="{toolbar: '#barOption'}" id="operation" style="width:60px"></th>
				</tr>
			</thead>
		</table>
		<!-- 新增弹出层显示内容 -->
		<div id="noticewin"class="layui-card" style="display:none">
  			<div class="layui-card-body">
				<span id="ln_title" style="font-size:18px; text-algin:center"></span><br>
				<span id="ln_context"></span><br>
				阅读量:<span id="ln_readnum"></span><br>
				公告序列号:<span id="ln_id"></span><br>
				发布者ID:<span id="lu_id"></span><br>
				发布日期:<span id="ln_date"></span>
  			</div>
		</div>

		<!--行内工具栏  -->
		<script type="text/html" id="barOption">
			<div class="layui-btn-group">
				<button type="button" class="layui-btn layui-btn-sm layui-bg-blue" lay-event="noticeevent">查看</button>
			</div>
		</script>
		<!-- 头部工具栏 -->
		<script type="text/html" id="toolbar">
			<div class="layui-btn-group">
				<button type="button" class="layui-btn" lay-event="checkevent">查找</button>
			</div>
		</script>

		<script type="text/javascript" src="static/lib/layui/layui.js"></script>
		<script type="text/javascript" id="toolbar">
			layui.use(['table', 'form'], function() {
				var table = layui.table;
				var form = layui.form;
				$ = layui.jquery;
				//监听工具条事件，删除表格中的一行数据
				table.on('tool(datalist)', function(obj) {
					var data = obj.data; //获取当前行的数据
					var layEvent = obj.event; //获取lay-event对应的值
					var tr = obj.tr; //获取当前行tr的DOM对象
					if (layEvent == 'noticeevent') {
						//#对应的是ID,.对应的是class
						$("#ln_id").text(data.n_id); //设置编辑框的修改前的属性
						$("#lu_id").text(data.u_id);
						$("#ln_date").text(data.n_date);
						$("#ln_readnum").text(data.n_readnum);
						$("#ln_context").text(data.n_context); //设置编辑框的修改前的属性
						$("#ln_title").text(data.n_title);
						var uri = "notice/look" + data.n_id;
						layer.open({
							  type:1,
							  title:"公告详情",
							  area:['800px','600px'],
							  content:$("#noticewin"),
							  btn:["确定"],
							  btn1:function(){
								  $.ajax({
									  type:'get',
									  url:uri,
									  success:function(d){
										  table.reload("datalist");
									  }
								  });
								  layer.closeAll();
								  
							  }
						  });
					}
				});
			})
		</script>
		<script type="text/javascript">
			var $ = layui.$;
			var table = layui.table;
			var layer = layui.layer;
			var form = layui.form;

			//头部工具栏
			table.on("toolbar(datalist)", function(obj) {
				var event = obj.event;
				var config = obj.config;
				var checkdata = table.checkStatus(config.id);
				if (event == "checkevent") {
					//点击查询
					var text = $("#checktext").val();
					var select = $("#selecttext").val();
					if (text == null) {
						table.reload("datalist");
					} else
						table.reload("datalist", {
							where: {
								'checktext': text,
								'selecttext': select
							},
							page: true
						});
				}
			});
		</script>
	</body>
</html>